Promise.myRace = function(array) {
    return new Promise((resolve, reject) => {
        for (let i = 0; i < array.length; i++) {
            const current = array[i]
            if (current instanceof Promise) {
                current.then(
                    value => resolve(value),
                    reason => reject(reason)
                )
            } else {
                resolve(current)
            }
        }
    })
}

var promise1 = new Promise(function(resolve, reject) {
    setTimeout(resolve, 500, 'one');
});

var promise2 = new Promise(function(resolve, reject) {
    setTimeout(resolve, 100, 'two');
});
Promise.race([promise1, promise2, 'p']).then(function(value) {
    console.log(value);
    // Both resolve, but promise2 is faster
  });